package com.inmobi.commons.internal;

import android.annotation.TargetApi;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build.VERSION;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.inmobi.commons.cache.CacheController;
import com.inmobi.commons.cache.CacheController.Validator;
import com.inmobi.commons.cache.ProductConfig;
import com.inmobi.commons.uid.UIDUtil;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.json.JSONException;
import org.json.JSONObject;

public class InternalSDKUtil
{
  public static final String DEBUG_TAG = "IMCOMMONS_3.7.0";
  public static final String INMOBI_SDK_RELEASE_VERSION = "3.7.0";
  public static final String PRODUCT_COMMONS = "commons";
  static CommonsConfig a = new CommonsConfig();
  static Context b = null;
  static CacheController.Validator c = new b();
  private static String d;
  private static Map<String, String> e = new HashMap();

  // ERROR //
  static String a(String paramString)
  {
    // Byte code:
    //   0: invokestatic 53	com/inmobi/commons/internal/InternalSDKUtil:a	()V
    //   3: new 55	org/json/JSONObject
    //   6: dup
    //   7: aload_0
    //   8: invokespecial 58	org/json/JSONObject:<init>	(Ljava/lang/String;)V
    //   11: astore_1
    //   12: getstatic 33	com/inmobi/commons/internal/InternalSDKUtil:a	Lcom/inmobi/commons/internal/CommonsConfig;
    //   15: aload_1
    //   16: invokevirtual 62	com/inmobi/commons/internal/CommonsConfig:setFromJSON	(Lorg/json/JSONObject;)V
    //   19: getstatic 33	com/inmobi/commons/internal/InternalSDKUtil:a	Lcom/inmobi/commons/internal/CommonsConfig;
    //   22: invokevirtual 66	com/inmobi/commons/internal/CommonsConfig:getTic	()Lcom/inmobi/commons/internal/ThinICEConfig;
    //   25: invokestatic 71	com/inmobi/commons/internal/ThinICE:a	(Lcom/inmobi/commons/internal/ThinICEConfig;)V
    //   28: invokestatic 53	com/inmobi/commons/internal/InternalSDKUtil:a	()V
    //   31: getstatic 33	com/inmobi/commons/internal/InternalSDKUtil:a	Lcom/inmobi/commons/internal/CommonsConfig;
    //   34: invokevirtual 75	com/inmobi/commons/internal/CommonsConfig:toJSON	()Lorg/json/JSONObject;
    //   37: invokevirtual 79	org/json/JSONObject:toString	()Ljava/lang/String;
    //   40: astore_3
    //   41: aload_3
    //   42: areturn
    //   43: astore 4
    //   45: ldc 8
    //   47: ldc 81
    //   49: invokestatic 87	com/inmobi/commons/internal/Log:debug	(Ljava/lang/String;Ljava/lang/String;)V
    //   52: aconst_null
    //   53: areturn
    //   54: astore_2
    //   55: aconst_null
    //   56: areturn
    //
    // Exception table:
    //   from	to	target	type
    //   3	12	43	java/lang/Exception
    //   31	41	54	org/json/JSONException
  }

  private static void a()
  {
    e = UIDUtil.getMap(getContext(), null);
  }

  public static boolean checkNetworkAvailibility(Context paramContext)
  {
    if (paramContext == null)
      return false;
    try
    {
      ConnectivityManager localConnectivityManager = (ConnectivityManager)paramContext.getSystemService("connectivity");
      if (localConnectivityManager.getActiveNetworkInfo() == null)
        return false;
      boolean bool = localConnectivityManager.getActiveNetworkInfo().isConnected();
      return bool;
    }
    catch (Exception localException)
    {
      Log.internal("IMCOMMONS_3.7.0", "Cannot check network state", localException);
    }
    return false;
  }

  public static boolean getBooleanFromJSON(JSONObject paramJSONObject, String paramString, boolean paramBoolean)
  {
    try
    {
      boolean bool = paramJSONObject.getBoolean(paramString);
      return bool;
    }
    catch (Exception localException)
    {
      try
      {
        Log.debug("IMCOMMONS_3.7.0", "JSON with property " + paramString + " found but has bad datatype(" + paramJSONObject.get(paramString).getClass() + "). Reverting to " + paramBoolean);
        return paramBoolean;
      }
      catch (JSONException localJSONException)
      {
      }
    }
    return paramBoolean;
  }

  public static CommonsConfig getConfig()
  {
    return a;
  }

  public static String getConnectivityType(Context paramContext)
  {
    int j;
    label90: label92: 
    do
    {
      try
      {
        if (paramContext.checkCallingOrSelfPermission("android.permission.ACCESS_NETWORK_STATE") == 0)
        {
          ConnectivityManager localConnectivityManager = (ConnectivityManager)paramContext.getSystemService("connectivity");
          if (localConnectivityManager != null)
          {
            NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
            int i = localNetworkInfo.getType();
            j = localNetworkInfo.getSubtype();
            if (i == 1)
              return "wifi";
            if (i == 0)
            {
              str = "carrier";
              if (j != 1)
                break label92;
              return "gprs";
              if (j != 0)
                break label90;
              return "carrier";
            }
          }
        }
      }
      catch (Exception localException)
      {
        Log.internal("IMCOMMONS_3.7.0", "Error getting the network info", localException);
        return null;
      }
      String str = null;
      return str;
      if (j == 2)
        return "edge";
    }
    while (j != 3);
    return "umts";
  }

  public static Context getContext()
  {
    return b;
  }

  // ERROR //
  public static int getDisplayRotation(Display paramDisplay)
  {
    // Byte code:
    //   0: ldc 193
    //   2: ldc 195
    //   4: aconst_null
    //   5: checkcast 197	[Ljava/lang/Class;
    //   8: invokevirtual 203	java/lang/Class:getMethod	(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
    //   11: astore 7
    //   13: aload 7
    //   15: astore_3
    //   16: aload_3
    //   17: ifnull +55 -> 72
    //   20: aload_3
    //   21: aload_0
    //   22: aconst_null
    //   23: checkcast 205	[Ljava/lang/Object;
    //   26: invokevirtual 211	java/lang/reflect/Method:invoke	(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;
    //   29: checkcast 213	java/lang/Integer
    //   32: invokevirtual 216	java/lang/Integer:intValue	()I
    //   35: istore 5
    //   37: iload 5
    //   39: ireturn
    //   40: astore_1
    //   41: ldc 193
    //   43: ldc 218
    //   45: aconst_null
    //   46: checkcast 197	[Ljava/lang/Class;
    //   49: invokevirtual 203	java/lang/Class:getMethod	(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;
    //   52: astore 6
    //   54: aload 6
    //   56: astore_3
    //   57: goto -41 -> 16
    //   60: astore 4
    //   62: sipush -999
    //   65: ireturn
    //   66: astore_2
    //   67: aconst_null
    //   68: astore_3
    //   69: goto -53 -> 16
    //   72: sipush -999
    //   75: ireturn
    //
    // Exception table:
    //   from	to	target	type
    //   0	13	40	java/lang/NoSuchMethodException
    //   20	37	60	java/lang/Exception
    //   41	54	66	java/lang/NoSuchMethodException
  }

  // ERROR //
  public static String getFinalRedirectedUrl(String paramString)
  {
    // Byte code:
    //   0: new 221	java/net/URL
    //   3: dup
    //   4: aload_0
    //   5: invokespecial 222	java/net/URL:<init>	(Ljava/lang/String;)V
    //   8: invokevirtual 226	java/net/URL:openConnection	()Ljava/net/URLConnection;
    //   11: checkcast 228	java/net/HttpURLConnection
    //   14: astore 4
    //   16: aload 4
    //   18: iconst_1
    //   19: invokevirtual 232	java/net/HttpURLConnection:setInstanceFollowRedirects	(Z)V
    //   22: aload 4
    //   24: iconst_0
    //   25: invokevirtual 235	java/net/HttpURLConnection:setUseCaches	(Z)V
    //   28: aload 4
    //   30: ldc 237
    //   32: invokevirtual 240	java/net/HttpURLConnection:setRequestMethod	(Ljava/lang/String;)V
    //   35: aload 4
    //   37: invokevirtual 243	java/net/HttpURLConnection:getResponseCode	()I
    //   40: sipush 200
    //   43: if_icmpne +47 -> 90
    //   46: aload 4
    //   48: invokevirtual 247	java/net/HttpURLConnection:getURL	()Ljava/net/URL;
    //   51: invokevirtual 248	java/net/URL:toString	()Ljava/lang/String;
    //   54: astore 5
    //   56: aload 4
    //   58: invokevirtual 251	java/net/HttpURLConnection:disconnect	()V
    //   61: aload 5
    //   63: areturn
    //   64: astore_1
    //   65: aconst_null
    //   66: astore_2
    //   67: aload_1
    //   68: astore_3
    //   69: ldc 8
    //   71: ldc 253
    //   73: aload_3
    //   74: invokestatic 125	com/inmobi/commons/internal/Log:internal	(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V
    //   77: aload_2
    //   78: areturn
    //   79: astore 6
    //   81: aload 5
    //   83: astore_2
    //   84: aload 6
    //   86: astore_3
    //   87: goto -18 -> 69
    //   90: aconst_null
    //   91: areturn
    //
    // Exception table:
    //   from	to	target	type
    //   0	56	64	java/lang/Exception
    //   56	61	79	java/lang/Exception
  }

  public static int getIntFromJSON(JSONObject paramJSONObject, String paramString, int paramInt)
  {
    try
    {
      int i = paramJSONObject.getInt(paramString);
      return i;
    }
    catch (Exception localException)
    {
      try
      {
        Log.debug("IMCOMMONS_3.7.0", "JSON with property " + paramString + " found but has bad datatype(" + paramJSONObject.get(paramString).getClass() + "). Reverting to " + paramInt);
        return paramInt;
      }
      catch (JSONException localJSONException)
      {
      }
    }
    return paramInt;
  }

  public static int getIntFromJSON(JSONObject paramJSONObject, String paramString, int paramInt1, int paramInt2, int paramInt3)
  {
    try
    {
      int i = paramJSONObject.getInt(paramString);
      if ((i > paramInt3) || (i < paramInt2))
        return paramInt1;
      return i;
    }
    catch (Exception localException)
    {
      try
      {
        Log.debug("IMCOMMONS_3.7.0", "JSON with property " + paramString + " found but has bad datatype(" + paramJSONObject.get(paramString).getClass() + "). Reverting to " + paramInt1);
        return paramInt1;
      }
      catch (JSONException localJSONException)
      {
      }
    }
    return paramInt1;
  }

  public static long getLongFromJSON(JSONObject paramJSONObject, String paramString, long paramLong)
  {
    try
    {
      long l = paramJSONObject.getLong(paramString);
      return l;
    }
    catch (Exception localException)
    {
      try
      {
        Log.debug("IMCOMMONS_3.7.0", "JSON with property " + paramString + " found but has bad datatype(" + paramJSONObject.get(paramString).getClass() + "). Reverting to " + paramLong);
        return paramLong;
      }
      catch (JSONException localJSONException)
      {
      }
    }
    return paramLong;
  }

  public static long getLongFromJSON(JSONObject paramJSONObject, String paramString, long paramLong1, long paramLong2, long paramLong3)
  {
    try
    {
      long l = paramJSONObject.getLong(paramString);
      if ((l > paramLong3) || (l < paramLong2))
        return paramLong1;
      return l;
    }
    catch (Exception localException)
    {
      try
      {
        Log.debug("IMCOMMONS_3.7.0", "JSON with property " + paramString + " found but has bad datatype(" + paramJSONObject.get(paramString).getClass() + "). Reverting to " + paramLong1);
        return paramLong1;
      }
      catch (JSONException localJSONException)
      {
      }
    }
    return paramLong1;
  }

  public static String getSavedUserAgent()
  {
    return d;
  }

  public static String getStringFromJSON(JSONObject paramJSONObject, String paramString1, String paramString2)
  {
    try
    {
      String str = paramJSONObject.getString(paramString1);
      return str;
    }
    catch (Exception localException)
    {
      try
      {
        Log.debug("IMCOMMONS_3.7.0", "JSON with property " + paramString1 + " found but has bad datatype(" + paramJSONObject.get(paramString1).getClass() + "). Reverting to " + paramString2);
        return paramString2;
      }
      catch (JSONException localJSONException)
      {
      }
    }
    return paramString2;
  }

  public static String getUserAgent(Context paramContext)
  {
    try
    {
      if (d == null)
        if (Build.VERSION.SDK_INT < 17)
          break label25;
      label25: for (d = a.a(paramContext); ; d = new WebView(paramContext).getSettings().getUserAgentString())
        return d;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      Log.internal("IMCOMMONS_3.7.0", "Cannot get user agent", localException);
    }
    return d;
  }

  public static void initialize(Context paramContext)
  {
    if (getContext() == null)
    {
      if (paramContext == null)
        throw new NullPointerException();
      b = paramContext;
    }
    try
    {
      CacheController.getConfig("commons", paramContext, e, c);
      return;
    }
    catch (CommonsException localCommonsException)
    {
      Log.debug("IMCOMMONS_3.7.0", "IMCommonsException caught with code " + localCommonsException.getCode());
    }
  }

  public static boolean isDefOrientationLandscape(int paramInt1, int paramInt2, int paramInt3)
  {
    if ((paramInt2 > paramInt3) && ((paramInt1 == 0) || (paramInt1 == 2)));
    while ((paramInt2 < paramInt3) && ((paramInt1 == 1) || (paramInt1 == 3)))
      return true;
    return false;
  }

  public static boolean isTablet(Context paramContext)
  {
    Display localDisplay = ((WindowManager)paramContext.getSystemService("window")).getDefaultDisplay();
    DisplayMetrics localDisplayMetrics = new DisplayMetrics();
    localDisplay.getMetrics(localDisplayMetrics);
    double d1 = localDisplayMetrics.widthPixels / localDisplayMetrics.xdpi;
    double d2 = localDisplayMetrics.heightPixels / localDisplayMetrics.ydpi;
    return Math.sqrt(d1 * d1 + d2 * d2) > 7.0D;
  }

  public static void populate(JSONObject paramJSONObject1, JSONObject paramJSONObject2, boolean paramBoolean)
    throws JSONException
  {
    Iterator localIterator = paramJSONObject1.keys();
    while (localIterator.hasNext())
    {
      String str = (String)localIterator.next();
      Object localObject1;
      Object localObject2;
      try
      {
        paramJSONObject2.get(str);
        try
        {
          localObject1 = paramJSONObject1.get(str);
          localObject2 = paramJSONObject2.get(str);
          if ((!(localObject1 instanceof JSONObject)) || (!(localObject2 instanceof JSONObject)))
            break label120;
          if (paramBoolean)
            break label103;
          paramJSONObject2.put(str, localObject1);
        }
        catch (JSONException localJSONException2)
        {
        }
      }
      catch (JSONException localJSONException1)
      {
        paramJSONObject2.put(str, paramJSONObject1.get(str));
      }
      continue;
      label103: populate((JSONObject)localObject1, (JSONObject)localObject2, true);
      continue;
      label120: paramJSONObject2.put(str, localObject1);
    }
  }

  public static JSONObject populateToNewJSON(JSONObject paramJSONObject1, JSONObject paramJSONObject2, boolean paramBoolean)
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    populate(paramJSONObject2, localJSONObject, false);
    populate(paramJSONObject1, localJSONObject, paramBoolean);
    return localJSONObject;
  }

  public static void setContext(Context paramContext)
  {
    if (b == null)
    {
      b = paramContext.getApplicationContext();
      a();
    }
    try
    {
      a(CacheController.getConfig("commons", paramContext, e, c).getData());
      return;
    }
    catch (CommonsException localCommonsException)
    {
    }
  }

  public static boolean validateAppId(String paramString)
  {
    if (paramString == null)
    {
      Log.debug("IMCOMMONS_3.7.0", "appId is null");
      return false;
    }
    if (paramString.matches("(x)+"))
    {
      Log.debug("IMCOMMONS_3.7.0", "appId is all xxxxxxx");
      return false;
    }
    if ("".equals(paramString.trim()))
    {
      Log.debug("IMCOMMONS_3.7.0", "appId is all blank");
      return false;
    }
    return true;
  }

  @TargetApi(17)
  static class a
  {
    static String a(Context paramContext)
    {
      return WebSettings.getDefaultUserAgent(paramContext);
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.inmobi.commons.internal.InternalSDKUtil
 * JD-Core Version:    0.6.2
 */